<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		// then解析
		const promise = new Promise((resolved, rejected) => {
			setTimeout(() => {
				if (true) {
					resolved(10)
				} else {
					rejected("失败")
				}
			}, 1000)
		}).then((res, err) => {
			console.log(res);
			console.log(err);
		})

		// async解析
		// await 需要在async里使用
		function fun() {
			return new Promise((resolved, rejected) => {
				setTimeout(() => {
					console.log('HXY');
					resolved('HXYSSD');
				}, 1000)
			})
		}
		async function fn() {
			console.log('123');
			let data = await fun()
			console.log('456');
			console.log(data);
		}
		fn()
	</script>
</body>

</html>